﻿using System.Collections.Generic;
using nRoute.SiteMaps;
using nRoute.ViewModels;
using nRoute.Samples.SiteMapClient.Views;

namespace nRoute.Samples.SiteMapClient.ViewModels
{
	public class MainPageViewModel : ViewModelBase
	{
		public MainPageViewModel()
		{
			LoadSiteMap();
		}

		public IEnumerable<SiteMapNode> SiteMapNodes { get; private set; }

#region Helpers

		private void LoadSiteMap()
		{
			// SiteMaps are loaded asynchronously 
			nRoute.SiteMaps.SiteMapService.LoadSiteMap((s) =>
			{
				if (s != null && s.RootNode != null)
				{
					this.SiteMapNodes = s.RootNode.ChildNodes;
					NotifyPropertyChanged(() => SiteMapNodes);
				}
			});
		}

#endregion

	}
}